﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using RVEAd.Helpers;
using RVEAd.Business;
using RVEAd.Business.Model;

namespace RVEAd.Forms
{
    public partial class FormReportChooser : Form
    {
        #region fields

        private RveBL rveBL;

        #endregion


        public FormReportChooser()
        {
            InitializeComponent();
            this.Load += new EventHandler(FormReportChooser_Load);
        }

        void FormReportChooser_Load(object sender, EventArgs e)
        {
            rveBL = new RveBL();

            LoadMonthAndYear();
            LoadClients();
        }

        void btnShowReport_Click(object sender, EventArgs e)
        {
            GenerateReport();
        }


        private void LoadClients()
        {
            List<Client> allClients = new List<Client>();
            allClients.Add(new Client() { Nume = "Toti clientii", ID = -1 });
            allClients.AddRange(rveBL.GetClients());

            comboClients.DataSource = allClients;
            comboClients.DisplayMember = "Nume";
            comboClients.ValueMember = "ID";
        }

        private void LoadMonthAndYear()
        {
            // bind luna
            comboLuna.DataSource = Common.MonthsList;
            comboLuna.DisplayMember = "MonthText";
            comboLuna.ValueMember = "MonthValue";
            comboLuna.SelectedValue = DateTime.Now.Month;

            // bind year
            comboAn.DataSource = Common.YearsList;
            comboAn.SelectedItem = DateTime.Now.Year;
        }

        private void GenerateReport()
        {
            var month = (int)comboLuna.SelectedValue;
            var year = (int)comboAn.SelectedValue;
            var clientId = (int)comboClients.SelectedValue;

            var dailyReportDS = rveBL.GetPlanForExport(year, month, clientId).ToDailyReportDS();

            Forms.FormReportViewer reportViewer = new FormReportViewer();
            reportViewer.InitReport(dailyReportDS.DailyReport, "DailyReportSource", Common.MonthsList[month-1].MonthText + " " + year);
            reportViewer.ShowDialog();
        }


    }
}
